package TestSystem;
import Problem.QuestionBank;
import Time.countDown;

import javax.swing.*;
import javax.swing.plaf.FontUIResource;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.FileNotFoundException;
import java.util.Enumeration;
import java.util.Timer;

/**
 * Creat with IntelliJ IDEA
 * Description:
 * Date:2021-12-13
 * Time:16:35
 */
public class ComputerTestSystem extends JFrame{

    Font font = new Font("Dialog",0,30);//设置默认字体
    QuestionBank questionBank = new QuestionBank();
    static Box west,east,south,center;
    countDown countDown = new countDown();//倒计时类
//    TestAction listener = new TestAction();

//    Thread setQuestion = new Thread(questionBank);
//    Thread time = new Thread(countDown);

    //构造方法
    public ComputerTestSystem() throws FileNotFoundException {

        InitGlobalFont(this.font);//调用InitGlobalFont()方法设置全局字体 - 避免重复设置字体
        setTitle("单机版java简易机考程序");
        JTextArea north = new JTextArea("欢迎使用java机考程序！",2,10);
        this.add(north, BorderLayout.NORTH);


        west =Box.createVerticalBox();//西边布局：总用时（总计时器）共有多少题，已经做的题
        JTextArea totalTime = new JTextArea("总用时");
        west.add(totalTime);
        JTextArea amount = new JTextArea("已经做的题");
        west.add(amount);
        this.add(west,BorderLayout.WEST);


//        time.start();
        east = Box.createVerticalBox();//东边布局：20秒倒计时显示 提交按钮
        countDown countDown = new countDown();

        JTextArea timeRemaining = new JTextArea(countDown.count(),1,10);//文本框 - 用于显示每一题剩余的时间
        east.add(timeRemaining);
        this.add(east,BorderLayout.EAST);


        south = Box.createVerticalBox();//南边布局：每一题的得分。
        JTextArea score = new JTextArea("每一题的得分",5,20);
        south.add(score);
        this.add(south,BorderLayout.SOUTH);


//        Box center = Box.createVerticalBox();//中间布局：题目：单选、多选、判断、每一次提交显示正误、得分，&正确答案
//        setQuestion.start();
        center = questionBank.setQuestion();
        this.add(center,BorderLayout.CENTER);

        validate();
        setBounds(30,30,1200,700);
        setVisible(true);

        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    }

    //修改swing全局字体 - 在main方法中生成其他GUI图形界面之前调用，可以将字体设置为我们传参的字体
    public static void InitGlobalFont(Font f){
        FontUIResource fontRes = new FontUIResource(f);
        for (Enumeration<Object> keys = UIManager.getDefaults().keys(); keys.hasMoreElements();) {
            Object key = keys.nextElement();
            Object value = UIManager.get(key);
            if (value instanceof FontUIResource) {
                UIManager.put(key, fontRes);
            }
        }
    }

    //内部类
    public static class TestAction implements ActionListener {

        @Override
        public void actionPerformed(ActionEvent e) {
            if(e.getSource()instanceof Timer){//时间到
                try {
                    QuestionBank q = new QuestionBank();
                    center = q.setQuestion();
                } catch (FileNotFoundException ex) {
                    ex.printStackTrace();
                }

            }
        }
    }

//    public static class TimeListener implements ActionListener{
//        @Override
//        public void actionPerformed(ActionEvent e) {
//            if (e.getSource())
//        }
//    }


    public QuestionBank getQuestionBank() {
        return questionBank;
    }

    public static void main(String[] args) {
        try {
            ComputerTestSystem test = new ComputerTestSystem();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
    }

}
